import numpy as np
import matplotlib.pyplot as plt
from time import clock
from search.all import *
from problem_agent import *
import problems
import heuristics
from sys import maxint 
from math import sqrt
reload(heuristics)
reload(problems)

class solution(ProblemAgent):
    
    def __init__(self, h):
        self.h = h
        
    def solve(self, problem_state, time_limit = NO_LIMIT):
        '''
        This is the method called by the runner of this agent.
        It includes the code that solves the problem.
        
        @param problem_state: Initial problem state.
        @param time_limit: The time limit for this agent.
        @return: A list of ProblemActions that solves the given problem.
        '''
        
        start = clock()
        res = None
        depth = sqrt(problem_state.width**2 + problem_state.height**2)
        while(clock()-start < time_limit):
            star = AStar(depth)
            res = star.find(problem_state,self.h)
        if res: return len(res)
        return None    
        

s = solution(heuristics.averaged_scaled_manhattan_dirt(3.5))
prob = problems.random_problem(10, 10)
print prob
for i in range(10):
    print 'time limit    :', i, '    suotion length:    ', s.solve(prob, i)
            
        